package com.ftqh.tutorial.security.entity;

import com.ftqh.tutorial.security.data.AbstractDomain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Administrator on 2017/6/13.
 */
@Entity
@Table(name = "sys_security_group")
@EntityListeners(AuditingEntityListener.class)
@Data
@EqualsAndHashCode(callSuper=true)
public class Group extends AbstractDomain<Integer> {

    private static final long serialVersionUID = -264032618713281284L;
    @Column(nullable = false)
    private String name;
    private String description;

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name="sys_security_group_authority",
            joinColumns={@JoinColumn(name="GROUP_ID")},
            inverseJoinColumns={@JoinColumn(name="ROLE_ID")}
    )
    private Set<Role> roles = new HashSet<>();

    @ManyToMany(mappedBy="groups")
    private Set<User> users = new HashSet<>();

}
